﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YTSK.Frm
{
    public partial class FrmSkTotal : Form
    {
        public FrmSkTotalCount voudefine;
        public FrmSkTotal()
        {
            InitializeComponent();
            this.Icon = YTSK.Properties.Resources.Fly;
            voudefine = new FrmSkTotalCount("sktotal", this.groupBox1);
            voudefine.Init();
            this.dtCheck.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            RefleshModel(this.dtCheck.Value);
            Application.DoEvents();
        }


        #region 刷新

        private void RefleshModel(DateTime dt)
        {
            try
            {
                var url = string.Format("{0}/api/oms/SKCompare/SKModel?token={1}&dDate={2}",
                        ServerConfig.ServerAddress, ServerConfig.GetToken(), dt.ToString("yyyy-MM-dd"));
                var s = Common.handleHttp.Get(url);
                var result = Common.handleJSON.DeserializeResult(s);
                if (result.result != 1) { MessageBox.Show("出错:" + result.resultdetail); return; }

                #region 显示数据
                var rds = result.GetListDic("SK_TotalModel");
                voudefine.Displaydata(rds, true);
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
        #endregion

        private void btCancel_Click(object sender, EventArgs e)
        {
            //var dr = MessageBox.Show("确认要取消校对么?", "提示", MessageBoxButtons.YesNo);
            //if (dr == DialogResult.No)
            //{ return; }
            this.Close();
        }

        private void btLogin_Click(object sender, EventArgs e)
        {
            this.Close();
            //var ss = voudefine.GetVouchData();
            //ss.Add("dDate", this.dtCheck.Value.ToString("yyyy-MM-dd"));
            //try
            //{
            //    var url = string.Format("{0}/api/oms/SKCompare/SKDataUpdate?token={1}",
            //            ServerConfig.ServerAddress, ServerConfig.Token);
            //    var s = Common.handleHttp.Post(ss, url);
            //    var result = Common.handleJSON.DeserializeResult(s);
            //    RefleshModel(this.dtCheck.Value);
            //    if (result.result != 1) { MessageBox.Show("出错:" + result.resultdetail); return; }
            //    else { MessageBox.Show("恭喜恭喜，数据校对完全正确"); this.Close(); }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message + ex.StackTrace);
            //}

        }

        private void btReflesh_Click(object sender, EventArgs e)
        {
            RefleshModel(this.dtCheck.Value);
        }
    }
}
